﻿using System;
using System.Collections.Generic;
using System.Text;
using dllLink;

namespace dllLink
{
    // Classe représentant un Asset au sens large
    // Il possède un nom, un type ("OPCVM", "EXCHANGERATE", ou "INTERESTRATE") et (éventuellement) une devise
    internal class Asset
    {
        string mvName;
        string mvType;
        string mvCurrency;

        private static string OPCVM = "OPCVM";
        private static string EXCHANGERATE = "EXCHANGERATE";
        private static string INTERESTRATE = "INTERESTRATE";

        public Asset(string theName, string theType, string theCurrency)
        {
            if (!(theType.Equals(OPCVM) || theType.Equals(EXCHANGERATE) || theType.Equals(INTERESTRATE)))
            {
                throw new Exception("The asset " + theName + " has an incorrect type (" + theType + ")");
            }
            mvName = theName;
            mvType = theType;
            mvCurrency = theCurrency;
        }

        public string mGetName()
        {
            return mvName;
        }

        public string mGetType()
        {
            return mvType;
        }

        public void mSetTypeUnderlying()
        {
            mvType = OPCVM;
        }

        public void mSetTypeExchangeRate()
        {
            mvType = EXCHANGERATE;
        }

        public void mSetTypeInterestRate()
        {
            mvType = INTERESTRATE;
        }

        public bool isUnderlying()
        {
            return (mvType.Equals(OPCVM));
        }

        public bool isExchangeRate()
        {
            return (mvType.Equals(EXCHANGERATE));
        }
        
        public bool isInterestRate()
        {
            return (mvType.Equals(INTERESTRATE));
        }

        public bool isEUR()
        {
            return (mvCurrency.ToUpper().Equals("€") || mvCurrency.ToUpper().Equals("EUR"));
        }

        public bool isUSD()
        {
            return (mvCurrency.ToUpper().Equals("$") || mvCurrency.ToUpper().Equals("USD"));
        }

        /// <summary>
        //returns the NAV of the Underlying on date theT (as given by the database)
        /// </summary>
        public double mNAV(DateTime theT) 
        {
            double myNAV = 0.0;
            moteurbd myBD = new moteurbd();
            myBD.Connect();
            myNAV = myBD.CoteLastDate(theT, mvName);
            myBD.Disconnect();
            return myNAV;
        }
       
        public double[] mVectNAV(DateTime[] theDates)
        {
            int myNbDates = theDates.Length;
            double[] myVectNAV = new double[myNbDates];
            moteurbd myBD = new moteurbd();
            myBD.Connect();
            for (int i=0; i <myNbDates; i++)
            {
                myVectNAV[i] = myBD.CoteDate(theDates[i], mvName);
            }
            myBD.Disconnect();
            return myVectNAV;
        }
    }
}
